package com.ww.util.guava;

import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;

import java.util.HashMap;
import java.util.Map;

public class MapDemo1 {

    public static void main(String[] args) {
        /**
         * map的交集、并集、差集
         */
        HashMap<String, Integer> mapA = Maps.newHashMap();
        mapA.put("a", 1);
        mapA.put("b", 2);
        mapA.put("c", 3);

        HashMap<String, Integer> mapB = Maps.newHashMap();
        mapB.put("b", 20);
        mapB.put("c", 3);
        mapB.put("d", 4);

        MapDifference<String, Integer> diffMap = Maps.difference(mapA, mapB);
        System.out.println(diffMap.areEqual());
        Map<String, MapDifference.ValueDifference<Integer>> entriesDiffering = diffMap.entriesDiffering();
        Map<String, Integer> entriesOnlyOnLeft = diffMap.entriesOnlyOnLeft();
        Map<String, Integer> entriesOnlyOnRight = diffMap.entriesOnlyOnRight();
        Map<String, Integer> entriesInCommon = diffMap.entriesInCommon();

        /**
         * 打印：{b=(2, 20)}
         */
        System.out.println(entriesDiffering);
        System.out.println("**************");
        /**
         * {a=1}
         */
        System.out.println(entriesOnlyOnLeft);
        System.out.println("**************");
        /**
         * {d=4}
         */
        System.out.println(entriesOnlyOnRight);
        System.out.println("**************");
        /**
         * {c=3}
         */
        System.out.println(entriesInCommon);
    }
}
